Design conceptual model
Translate conceptual model into a mathematical representation
Choose programming language
Define inputs (data type, units)
Define output (data type, units)
Define model structure
Write model
Document the model (meta data)
Test model
Hierarchical in level of details
Big chunks (coarse detail) -> progressively finer
Note ‘tasks’ that need to be repeated
All tasks should have inputs and outputs
Often more complicated than a simple regression…
So we need to think through what the relationships are; the processes are that we want to take in to account
Conceptual models are a good place to start
Some model designers uses standard symbols for the different model components
Building Models
Conceptual Models
Pictorial representation of how you think about your system, and what needs to be included in the model to answer your questions (or achieve your modelling goal)
There are many software tools available for generating conceptual models, I like
[Diagrams.net]{https://www.diagrams.net/}
More complex model couple sub-models
How do ecological and human factors interact to influence fire regimes
Impact of climate on almond productivity
What is almond productivity?
What is climate?
Functions!
The basic building blocks of models
Functions can be written in all languages; in many languages (object-oriented) like C++, Python, functions are also objects
Functions are the “boxes” of the model - the transfer function that takes inputs and returns outputs
More complex models - made up of multiple functions; and nested functions (and main functions that call/user other functions and control the flow - the arrows between boxes)
Decide on
Inputs and parameters
Outputs
Data types, units (time and space aggregation), names should be (use descriptive names)
input (mean growing season temperature - growT);
parameter (senT - sensitivity to temperature
output (growth )
(all float)
inputs (temperature (growT), Plant type)
parameters
output ( growth)
IMPORTANT
Place each function in its own file (x.R), and put all functions for a given project in R subdirectory
Input: Reservoir height (height) and flow rate (flow)
Output: Instantaneous power generation (W/s)
Parameters: K Efficiency , ρ (density of water), g (acceleration due to gravity)
P = ρ * h * r * g * K Efficiency;
P is Power in watts, ρ is the density of water (~1000 kg/m3), h is height in meters, r is flow rate in cubic meters per second, g is acceleration due to gravity of 9.8 m/s2, K Efficiency is a coefficient of efficiency ranging from 0 to 1.
This is a static (one point in time), deterministic, lumped (one place) model; its more or less physically based
Inputs/parameters are height, flow, rho, g, and K
For some (particularly parameters) we provide default values by assigning them a value (e.g Keff = 0.8), but we can overwrite these
Body is the equations between { and } return tells R what the output is
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.2 ──
## ✔ ggplot2 3.4.0 ✔ purrr 1.0.0
## ✔ tibble 3.1.8 ✔ dplyr 1.0.10
## ✔ tidyr 1.2.1 ✔ stringr 1.5.0
## ✔ readr 2.1.3 ✔ forcats 0.5.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
power_gen = function(height, flow, rho=1000, g=9.8, Keff=0.8) {
result = rho * height * flow * g * Keff
return(result)
}
power_gen(height=10, flow=2)## [1] 156800
## [1] 156800
## [1] 67200
# generate some test data
measured_height=runif(min=1, max=100, n=20)
# create a data frame to store results of model run
power_estimate = cbind.data.frame(height=measured_height, estimate=power_gen(height=measured_height, flow=2))
# graph
ggplot(power_estimate,aes(height, estimate) )+geom_point()+labs(y="power in W/x", x="height (m)")#' Power Generation
#'
#' This function computes instantaneous power generation
#’ from a reservoir given its height and flow rate into turbines
#' @param rho Density of water (kg/m3) Default is 1000
#' @param g Acceleration due to gravity (m/sec2) Default is 9.8
#' @param Kefficiency Turbine Efficiency (0-1) Default is 0.8
#' @param height height of water in reservoir (m)
#' @param flow flow rate (m3/sec)
#' @author Naomi
#' @examples power_gen(20, 1)
#' @return Power generation (W/s)
power_gen = function(height, flow, rho=1000, g=9.8, Keff=0.8) {
# calculate power
result = rho * height * (flow) * g * Keff
return(result)
}[esm232_examples github site]{https://github.com/naomitague/ESM232_Examples.git}
You can clone this repository and then pull before class to get example code and data
Just remember that git does not like having nest repositories - so keep working respoistories in separate directories